﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using System.Diagnostics;
using System.ServiceProcess;
using System.Configuration;
namespace PanasonicWarranty.UI
{
    public partial class TrackingService : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        [WebMethod]
        public static object GetService()
        {
            string serviceName = "SMSPanasonicService";
            string serviceStatus;
            var service = ServiceController.GetServices().FirstOrDefault(p => p.ServiceName == serviceName);
            if (service != null)
            {
                if (service.Status == ServiceControllerStatus.Running)
                {
                    serviceStatus = "Running";
                }
                else
                {
                    serviceStatus = "Don't run";
                }
            }
            else
            {
                serviceStatus = "Service not exists";
            }

            return new ServiceInfo()
            {
                ServiceName = serviceName,
                ServiceStatus = serviceStatus
            };

        }

        internal class ServiceInfo
        {
            public string ServiceName;
            public string ServiceStatus;
        }
    }
}